package com.znsd.zl.sys.sms.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.znsd.zl.sys.sms.entity.SmsLogEntity;
import com.znsd.zl.sys.sms.service.ISmsLogService;
import com.znsd.zl.utils.GenerateQueryWrapper;
import com.znsd.zl.utils.BaseController;
import com.znsd.zl.utils.PageUtils;
import com.znsd.zl.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName SysSmsLogController
 * @Description 系统短信日志控制器接口
 * @author jaypdd
 * @email jaypdd@163.com
 * @date 2020-08-19 09:43:32
 * @Version v1.0
 */
@Slf4j
@RestController
@RequestMapping("/sys/smsLog")
public class SmsLogController extends BaseController<ISmsLogService, SmsLogEntity, Integer> {

	/**
	 * 分页条件查询
	 * @param smsLogEntity  根据字段值进行分页条件查询
	 * @param pageNum       当前请求页码
	 * @param pageSize      每页请求记录数数量
	 * @return 返回分页后的短信日志列表
	 */
	@GetMapping("/pageFind")
	public R pageFind(SmsLogEntity smsLogEntity,
					@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
					@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
					HttpServletRequest req) {
		PageUtils pageUtils = null;
		try{
			// 生成QueryWrapper条件构造器
			QueryWrapper<SmsLogEntity> queryWrapper = GenerateQueryWrapper
					.initQueryWrapper(smsLogEntity, req.getParameterMap());
			pageUtils = new PageUtils(service.page(new Page<SmsLogEntity>(pageNum, pageSize), queryWrapper));
		}catch (Exception e) {
			e.printStackTrace();
			return R.error("服务器异常，请稍后重试");
		}
		return R.ok().put("page", pageUtils);
	}
}
